package com.lee.common.utils

import android.app.Activity
import android.content.Context
import android.os.Parcelable
import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.launcher.ARouter
import java.io.Serializable

object Skipping {

    private var util = AntiShake()
    private var checkTime = 1200

    fun start(path: String) {
        if (util.check(path, checkTime)) return
        ARouter.getInstance().build(path).navigation()
    }

    fun startCheck(path: String) {
        if (util.check(path, checkTime)) return
        if (!SharedPreUtils.getBoolean(isAmoebaWareHouse, false)) return
        ARouter.getInstance().build(path).navigation()
    }

    fun start(path: String, key: String, value: Parcelable?) {
        if (util.check(path, checkTime)) return
        ARouter.getInstance().build(path).withParcelable(key, value).navigation()
    }


    fun navWeb(value: String?, context: Context) {
        if (util.check(ACTIVITY_WEB2, checkTime)) return
        ARouter.getInstance().build(ACTIVITY_WEB2).withString("link", value).navigation(context)
    }

    fun navWeb1(value: String?, context: Context) {
        if (util.check(ACTIVITY_WEB, checkTime)) return
        ARouter.getInstance().build(ACTIVITY_WEB).withString("link", value).navigation(context)
    }

    fun navScan(value: Int, value2: Int, applyType: String, context: Activity) {
        if (util.check(ACTIVITY_WAREHOUSE_QRCODE_SCAN, checkTime)) return
        ARouter.getInstance().build(ACTIVITY_WAREHOUSE_QRCODE_SCAN).withInt("wareId", value)
            .withInt("applyDeviceId", value2)
            .withString("applyType", applyType)
            .navigation(context,201)
    }

    fun start(path: String, key: String, value: Serializable?) {
        if (util.check(path, checkTime)) return
        ARouter.getInstance().build(path).withSerializable(key, value).navigation()
    }

    fun start(path: String, key: String, value: Serializable?, context: Context) {
        if (util.check(path, checkTime)) return
        ARouter.getInstance().build(path).withSerializable(key, value).navigation(context)
    }

    fun start(path: String, flags: Int) {
        if (util.check(path, checkTime)) return
        ARouter.getInstance().build(path).addFlags(flags).navigation()
    }

    fun start(path: String, key: String, value: String) {
        if (util.check(path, checkTime)) return
        ARouter.getInstance().build(path).withString(key, value).navigation()
    }

    fun start(path: String, key: String, value: Int, key2: String, value2: Int, context: Context) {
        if (util.check(path, checkTime)) return
        ARouter.getInstance().build(path).withInt(key, value).withInt(key2, value2)
            .navigation(context)
    }

    fun start(path: String, key: String, value: String, context: Context) {
        if (util.check(path, checkTime)) return
        ARouter.getInstance().build(path).withString(key, value).navigation(context)
    }

    fun start(path: String, key: String, value: Int) {
        if (util.check(path, checkTime)) return
        ARouter.getInstance().build(path).withInt(key, value).navigation()
    }

    fun start(path: String, key: String, value: Int, context: Context) {
        if (util.check(path, checkTime)) return
        ARouter.getInstance().build(path).withInt(key, value).navigation(context)
    }

    fun start(
        path: String,
        key: String,
        value: Int,
        key2: String,
        value2: Serializable?,
        context: Context
    ) {
        if (util.check(path, checkTime)) return
        ARouter.getInstance().build(path).withInt(key, value).withSerializable(key2, value2)
            .navigation(context)
    }

    fun start(
        path: String,
        key: String,
        value: Int,
        key2: String,
        value2: Serializable?,
        key3: String,
        value3: Serializable?,
        context: Context
    ) {
        if (util.check(path, checkTime)) return
        ARouter.getInstance().build(path).withInt(key, value).withSerializable(key2, value2)
            .withSerializable(key3, value3).navigation(context)
    }

    fun getFragment(path: String, key: String, value: Int): Fragment {
        return ARouter.getInstance().build(path).withInt(key, value).navigation() as Fragment
    }

}